Don't require database access in ApiMainTest
authorKunal Mehta <legoktm@gmail.com>
Sun, 29 Mar 2015 08:41:38 +0000 (01:41 -0700)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 2 Apr 2015 15:32:06 +0000 (15:32 +0000)
It's still slow though because ApiTestCase does expensive things in
setUp(), but nothing in these tests need database access anymore.

Change-Id: Iaf431cc62fe23154c42967e6391c533fe1c5346e

tests/phpunit/includes/api/ApiMainTest.php

index e91edcb..7a03f7d 100644 (file)
@@ -2,7 +2,6 @@
 
 /**
  * @group API
- * @group Database
  * @group medium
  *
  * @covers ApiMain
@@ -23,20 +22,12 @@ class ApiMainTest extends ApiTestCase {
        }
 
        public static function provideAssert() {
-               $anon = new User();
-               $bot = new User();
-               $bot->setName( 'Bot' );
-               $bot->addToDatabase();
-               $bot->addGroup( 'bot' );
-               $user = new User();
-               $user->setName( 'User' );
-               $user->addToDatabase();
                return array(
-                       array( $anon, 'user', 'assertuserfailed' ),
-                       array( $user, 'user', false ),
-                       array( $user, 'bot', 'assertbotfailed' ),
-                       array( $bot, 'user', false ),
-                       array( $bot, 'bot', false ),
+                       array( false, array(), 'user', 'assertuserfailed' ),
+                       array( true, array(), 'user', false ),
+                       array( true, array(), 'bot', 'assertbotfailed' ),
+                       array( true, array( 'bot' ), 'user', false ),
+                       array( true, array( 'bot' ), 'bot', false ),
                );
        }
 
@@ -45,11 +36,17 @@ class ApiMainTest extends ApiTestCase {
         *
         * @covers ApiMain::checkAsserts
         * @dataProvider provideAssert
-        * @param User $user
+        * @param bool $registered
+        * @param array $rights
         * @param string $assert
         * @param string|bool $error False if no error expected
         */
-       public function testAssert( $user, $assert, $error ) {
+       public function testAssert( $registered, $rights, $assert, $error ) {
+               $user = new User();
+               if ( $registered ) {
+                       $user->setId( 1 );
+               }
+               $user->mRights = $rights;
                try {
                        $this->doApiRequest( array(
                                'action' => 'query',